package code15Lambda表达式;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

/**
 * @author 黄衡熙
 * @version 1.0
 */
public class Test03_供给型接口 {

    public static void main(String[] args) {
        // 匿名内部类
        List<String> list = testSupplier(new Supplier<List<String>>() {
            @Override
            public List<String> get() {
                return Arrays.asList("admin", "jack", "tom", "lucy");
            }
        });
        System.out.println(list);
        // Lambda表达式用法
        List<String> list2 = testSupplier(() -> Arrays.asList("南京", "北京", "苏州", "常州", "泰州", "徐州", "杭州", "无锡"));
        System.out.println(list2);
    }


    /**
     * 供给型接口
     * 其泛型类型与方法返回值类型一致
     * @param supplier
     * @return
     */
    public static List<String> testSupplier(Supplier<List<String>> supplier) {
        return supplier.get();
    }

}